import smtplib
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

msg = MIMEMultipart()
msg['subject'] = "欢迎你，张三"
msg['from'] = "zjueman@qq.com"
msg['to'] = 'zjueman@qq.com'

# 定义HTML页面的内容
html_content = """\
<html>
  <body>
    <p>你好,<br>
       <b>欢迎光临演唱会，请在附件中查收您的门票~</b><br>
       点这里了解更多：<a href="http://www.maishu.com">演唱会主页</a> 
    </p>
  </body>
</html>
"""

# 创建MIMEText的时候，用第二个参数指明这是html
html_part = MIMEText(html_content, 'html')
msg.attach(html_part)

filename = '张三.docx'
with open(filename, 'rb') as f:
    part = MIMEApplication(f.read())
    part.add_header('Content-Disposition', 'attachment', filename=filename)
    msg.attach(part)

    server = smtplib.SMTP(host='smtp.qq.com', port=587)
    server.login("zjueman@qq.com", 'uqgomqliyznkbidi')
    server.send_message(msg)

    server.quit()

